<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'addScrap.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<style type="text/css">
body{
font-size:12px;
}
div{
	width:500px;
	height:500px;
	
}
table{
	margin-left:50px;
	font-size:13px;
}

.bt{
width:80px;
margin-left:60px;
margin-top:30px;
}
td{
height:45px;
text-align:left;
}

</style>
  </head>
  
  <body>
  <div>
 <form action="jsp/scrap/scrapadd">
   
   <table>
   <tr><td>报损详情：</td>
   <td><input type="text"  name="sdetail"/></td>

   </tr>
   <tr><td>图书编号：</td>
   <td><input type="text" id="bid" name="bid"/></td>
   <td id="show"></td>
   </tr>
   <tr>
   <td> 报损人：</td>
    <td><input type='text' name='uuser' value="${ sessionScope.username}" readonly/></td>
    </tr>
   <tr><td>报损时间：</td>
   <td><input type="text" name="time "onclick="new Calendar().show(this);" readonly="readonly"/></td>
   </tr>
   <tr><td>报损数量：</td>
   <td><input type="text" id="snum" name="snum"/></td>
   <td id="show2"></td>
   </tr>
   </table>
     <input  type='submit' value='提交' class="bt" id="btn"/>
  <input  type='button' value='重置' class="bt" onclick="res()"/>
   </form>
   </div>
  </body>
  <script type="text/javascript" src="js/calendar.js"></script>
    <script type="text/javascript" src="js/jquery-1.7.2.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
 		 $("#btn").attr("disabled", true);
 		 
 $("#bid").blur(function(){
  var t=/^[0-9]*$/;
  var obj={};
  	obj.bid=$(this).val();
  	if($(this).val()==""||$.trim($(this).val()).length==0){
  	$('#show').text("请输入图书编号").css("color","red");
  	$("#btn").attr("disabled", true);
  	}else if(t.test($(this).val())){
  		$.post('<%= basePath%>jsp/book/bookjson_list',obj,cl,'json');
  	}else{
  		$('#show').text("请输入数字").css("color","red");
  	$("#btn").attr("disabled", true);
  	}
  });
  $("#snum").blur(function(){
  var t=/^[0-9]*$/;
  if($("#bid").val()==""){
  $('#show2').text("请输入图书编号").css("color","red");
	 	$("#btn").attr("disabled", true);
  }else if(!t.test($(this).val())){
		$('#show2').text("请输入数字").css("color","red");
	 	$("#btn").attr("disabled", true);
  	}else if($(this).val()!=""&&$.trim($(this).val()).length!=0){
  				if($(this).val()=="0"){
  					$('#show2').text("不能为0").css("color","red");
  					$("#btn").attr("disabled", true);
  				}else{
  			 		var obj={};
  					obj.snum=$(this).val();
  					obj.bid=$("#bid").val();
  					$.post('<%= basePath%>jsp/scrap/scrap_json',obj,num,'json');
  					}	
  		}else{
  			$('#show2').text("默认为1本").css("color","red");
  			if($('#show').text()=="Ok")
			$("#btn").attr("disabled", false);
  	}
  });
  
  });
  
  function cl(data){
  	if(data.state=="1"){
  	$('#show').text("Ok").css("color","green");
  	if($('#show2').text()!="报损数量>库存数量" )
  	$("#btn").attr("disabled", false);
  	}else if(data.state=="0"){
  	$('#show').text("没有此图书").css("color","red");
  		  $("#btn").attr("disabled", true);
  	}
  	}
  	
  	
  function num(data){

  	if(data.state=="1"){
  	$('#show2').text("Ok").css("color","green");
  	if($('#show').text()=="Ok" )
    	$("#btn").attr("disabled", false);
  	}else if(data.state=="0"){
  	$('#show2').text("报损数量>库存数量").css("color","red");
  		  $("#btn").attr("disabled", true);
  	}
  	}
  	function res(){
  	$("#btn").attr("disabled", true);
$('table input').val("");
	$('#show').text("");
	$('#show2').text("");

  	}
    
    </script>
</html>
